package cn.tedu.shoppingmall.mapper;

import cn.tedu.shoppingmall.vo.Address;
import cn.tedu.shoppingmall.vo.User;
import cn.tedu.shoppingmall.vo.UserDetail;
import org.apache.ibatis.annotations.Insert;

import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mapstruct.Mapper;

import java.util.List;
//用户地址信息数据库增删改查操作
@Mapper
public interface AddressMapper {
    //增加新地址
    @Insert("insert into address(addressname,remark,username,userid) values(#{addressname},#{remark},#{username},#{userid})")
    void insertAddress(Address address);

    //根据用户id修改地址信息
    @Update("update address set addressname=#{addressname} where userid=#{userid}")
    void updateAddressname(Address address);
    //根据用户id修改地址备注信息
    @Update("update address set remark=#{remark} where userid=#{userid}")
    void updateRemark(Address remark);
    //根据用户id修改地址的用户名字(用户修改个人信息后,需要做得操作)
    @Update("update address set username=#{username} where userid=#{userid}")
    void updateUsernameByUserId(UserDetail userDetail);

    //根据用户名字查询所属地址信息
    @Select("select addressname,remark,username from address where username=#{username}")
    List<Address> findAddressByUserUsername(String username);


}
